home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / share / sql-bench / test-alter-table.z / test-alter-table
Encoding:
Text File  |  1999-10-18  |  3.9 KB  |  166 lines

  1. #!/bin/perl5
  2. #
  3. # Test of alter table
  4. #
  5.  
  6. ##################### Standard benchmark inits ##############################
  7.  
  8. use DBI;
  9. use Benchmark;
  10.  
  11. $opt_start_field_count=8;    # start with this many fields
  12. $opt_loop_count=20;        # How many tests to do
  13. $opt_row_count=1000;         # Rows in the table
  14. $opt_field_count=1000;        # Add until this many fields.
  15.  
  16. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  17. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  18.  
  19. $opt_field_count=min($opt_field_count,$limits->{'max_columns'},
  20.              ($limits->{'query_size'}-30)/14);
  21. $opt_start_field_count=min($opt_start_field_count,$limits->{'max_index'});
  22.  
  23. if ($opt_small_test)
  24. {
  25.   $opt_row_count/=10;
  26.   $opt_field_count/=10;
  27. }
  28.  
  29. if (!$limits->{'alter_table'})
  30. {
  31.   print("Some of the servers given with --cmp or --server doesn't support ALTER TABLE\nTest aborted\n\n");
  32.   $start_time=new Benchmark;
  33.   end_benchmark($start_time);
  34.   exit 0;
  35. }
  36.  
  37. print "Testing of ALTER TABLE\n";
  38. print "Testing with $opt_field_count columns and $opt_row_count rows in $opt_loop_count steps\n";
  39.  
  40. ####
  41. #### Create a table and fill it with data
  42. ####
  43.  
  44. $dbh = $server->connect();
  45. @fields=();
  46. @index=();
  47. push(@fields,"i1 int not null");
  48. for ($i=2 ; $i <= $opt_start_field_count ; $i++)
  49. {
  50.   push(@fields,"i${i} int not null");
  51. }
  52. $field_count= $opt_start_field_count;
  53.  
  54. $start_time=new Benchmark;
  55.  
  56. $dbh->do("drop table bench");
  57. do_many($dbh,$server->create("bench",\@fields,\@index));
  58.  
  59. print "Insert data into the table\n";
  60.  
  61. $loop_time=new Benchmark;
  62. for ($i=0 ; $i < $opt_row_count ; $i++)
  63. {
  64.   $query="insert into bench values ( " . ("$i," x ($opt_start_field_count-1)) . "$i)";
  65.   $dbh->do($query) or die $DBI::errstr;
  66. }
  67. $end_time=new Benchmark;
  68.  
  69. print "Time for insert ($opt_row_count)",
  70.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  71.  
  72.  
  73. ####
  74. #### Add fields to the table.
  75. ####
  76.  
  77. $loop_time=new Benchmark;
  78. $add= int(($opt_field_count-$opt_start_field_count)/$opt_loop_count)+1;
  79.  
  80.  
  81. $add=1 if (!$limits{'alter_add_multi_col'});
  82. $multi_add=$server->{'limits'}->{'alter_add_multi_col'} == 1;
  83.  
  84. $count=0;
  85. while ($field_count < $opt_field_count)
  86. {
  87.   $count++;
  88.   $end=min($field_count+$add,$opt_field_count);
  89.   $fields="";
  90.   $tmp="ADD ";
  91.   while ($field_count < $end)
  92.   {
  93.     $field_count++;
  94.     $fields.=",$tmp i${field_count} integer";
  95.     $tmp="" if (!$multi_add);            # Adabas
  96.   }
  97.   do_query($dbh,"ALTER TABLE bench " . substr($fields,1));
  98. }
  99.  
  100. $end_time=new Benchmark;
  101. print "Time for alter_table_add ($count): " .
  102.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  103.  
  104. ####
  105. #### Test adding and deleting index on the first $opt_start_fields
  106. ####
  107.  
  108. $loop_time=new Benchmark;
  109.  
  110. for ($i=1; $i < $opt_start_field_count ; $i++)
  111. {
  112.   $dbh->do("CREATE INDEX bench_ind$i ON bench (i${i})") || die $DBI::errstr;
  113. }
  114.  
  115. $end_time=new Benchmark;
  116. print "Time for create_index ($opt_start_field_count): " .
  117.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  118.  
  119. $loop_time=new Benchmark;
  120. for ($i=1; $i < $opt_start_field_count ; $i++)
  121. {
  122.   $dbh->do($server->drop_index("bench","bench_ind$i")) || die $DBI::errstr;
  123. }
  124.  
  125. $end_time=new Benchmark;
  126. print "Time for drop_index ($opt_start_field_count): " .
  127.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  128.  
  129. ####
  130. #### Delete fields from the table
  131. ####
  132.  
  133. goto skip_dropcol if (!$limits->{'alter_table_dropcol'});
  134.  
  135. $loop_time=new Benchmark;
  136.  
  137. $count=0;
  138. while ($field_count > $opt_start_field_count)
  139. {
  140.   $count++;
  141.   $end=max($field_count-$add,$opt_start_field_count);
  142.   $fields="";
  143.   while(--$field_count >= $end)
  144.   {
  145.     $fields.=",DROP i${field_count}";
  146.   }
  147.   $dbh->do("ALTER TABLE bench " . substr($fields,1)) || die $DBI::errstr;
  148. }
  149.  
  150. $end_time=new Benchmark;
  151. print "Time for alter_table_drop ($count): " .
  152.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  153.  
  154. skip_dropcol:
  155.  
  156. ################################ END ###################################
  157. ####
  158. #### End of the test...Finally print time used to execute the
  159. #### whole test.
  160.  
  161. $dbh->do("drop table bench");
  162.  
  163. $dbh->disconnect;
  164.  
  165. end_benchmark($start_time);
  166.